<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\massage\controller;

class IndexArticle extends \app\ApiRest
{
    protected $model;
    protected $sub_list_model;
    protected $sub_data_model;
    protected $field_model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\massage\model\ArticleList();
        $this->sub_list_model = new \app\massage\model\SubList();
        $this->sub_data_model = new \app\massage\model\SubData();
        $this->field_model = new \app\massage\model\FieldList();
    }
    public function articleList()
    {
        $input = $this->_param;
        $dis[] = ["uniacid", "=", $this->_uniacid];
        $dis[] = ["status", "=", 1];
        if(!empty($input["title"])) {
            $dis[] = ["title", "like", "%" . $input["title"] . "%"];
        }
        $data = $this->model->dataList($dis, 10);
        return $this->success($data);
    }
    public function articleInfo()
    {
        $input = $this->_param;
        $dis = ["id" => $input["id"]];
        $data = $this->model->dataInfo($dis);
        return $this->success($data);
    }
    public function subArticleForm()
    {
        $input = $this->_input;
        $insert = ["uniacid" => $this->_uniacid, "user_id" => $this->getUserId(), "article_id" => $input["article_id"]];
        $this->sub_list_model->dataAdd($insert);
        $id = $this->sub_list_model->getLastInsID();
        foreach ($input["sub_data"] as $k => $v) {
            $insert_data[$k] = ["uniacid" => $this->_uniacid, "sub_id" => $id, "key" => $v["key"], "value" => $v["value"], "field_id" => $v["field_id"], "field_type" => $v["field_type"]];
        }
        $this->sub_data_model->saveAll($insert_data);
        return $this->success(true);
    }
}

?>